<?php

namespace App\Console\Commands;

use App\Good;
use App\OrderGoods;
use Illuminate\Console\Command;

class OrderGoodUrl extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'Order:good {url}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        OrderGoods::chunk(100,function($orderGood){
            foreach ($orderGood as $v){
                $goodObject=$v->good_object;

                $goodObject['goods_thumbnail']=str_replace($this->argument('url'),config('app.url'),$goodObject['goods_thumbnail']);

                $v->good_object=json_encode($goodObject);
                $v->save();
            }
        });
         foreach (Good::all() as $v){
             $v->detail=str_replace($this->argument('url'),config('app.url'),$v->detail);
             $v->save();
         }
         $this->info('完成');
    }
}
